/**
 *
 */
package com.wedroid.r2d2.service.impl;

import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wedroid.entity.command.Command;
import com.wedroid.entity.contact.Contacter;
import com.wedroid.r2d2.dao.CommandDaoSupport;
import com.wedroid.r2d2.service.CommandService;

/**
 * @author lute
 */
@Service("commandService")
public class CommandServiceImpl implements CommandService {

    @Autowired
    private CommandDaoSupport commandDaoSupport;

    /* (non-Javadoc)
     * @see com.wedroid.r2d2.service.CommandService#getCommand(com.wedroid.entity.contact.Contacter, java.lang.String)
     */
    public Optional<Command> getCommand(Contacter contacter, String keyword) {
        Command command = commandDaoSupport.getExclusiveCommand(contacter.getId(), keyword);
        if (command == null) {
            command = commandDaoSupport.getGeneralCommand(keyword);
        }
        return Optional.ofNullable(command);
    }

}
